﻿

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using VMC.Domain.Entity;
using VMC.Domain.Service;
using VMC.Domain.Service.Abstract;
using VMC.Domain.Model.Service.Abstract;
using VMC.Domain.Model.Account;

namespace VMC.Domain.Model.Service
{
    public class AccountModelService : ModelService, IAccountModelService
    {
        private IUserService iUserService;
        
        public AccountModelService() : this(new UserService()) { }
        public AccountModelService(IUserService Service)
        {
            iUserService = Service;
        }
        public bool Delete(int ID)
        {
            //Implement this
            return iUserService.Delete(ID);
        }
        public override Dictionary<string, string> GetErrors()
        {
            return iUserService.GetValidationErrors();
        }


        public bool RegisterUser(Register Model)
        {
            return iUserService.Create(
                    Model.UserName, 
                    Model.Password, 
                    Model.Email, 
                    Model.FirstName, 
                    Model.LastName, 
                    Model.AddressLine1, 
                    Model.AddressLine2, 
                    Model.CityStateZip, 
                    Model.WorkPhone, 
                    "Registered", 
                    true
                );
        }

        public bool ValidateLogin(LogOn Model)
        {
            return iUserService.ValidateLogin(Model.UserName, Model.Password);
        }

        public UpdateProfile GetUserProfile(string UserName)
        {
            User mUser = iUserService.Find(UserName);
            UpdateProfile mProfile = new UpdateProfile();
            if (mUser != null)
            {
                mProfile.FirstName = mUser.FirstName;
                mProfile.LastName = mUser.LastName;
                mProfile.Email = mUser.Email;
                mProfile.ID = mUser.ID;
                mProfile.AddressLine1 = mUser.AddressLine1;
                mProfile.AddressLine2 = mUser.AddressLine2;
                mProfile.CityStateZip = mUser.CityStateZip;
                mProfile.WorkPhone = mUser.WorkPhone;
            }
            return mProfile;
        }

        public bool UpdateProfile(UpdateProfile Model)
        {
            return iUserService.UpdateProfile(Model.ID, Model.Email, Model.FirstName, Model.LastName, Model.AddressLine1, Model.AddressLine2, Model.CityStateZip, Model.WorkPhone);   
        }

        public bool ChangePassword( ChangePassword Model)
        {
            return iUserService.ChangePassword(Model.UserName, Model.OldPassword, Model.NewPassword);
        }
        //public UserManagement GetList()
        //{
        //    mManagement.Reset();
        //    mManagement.Items = new UserList();
        //    List<AddEditUser> mUserList = new List<AddEditUser>();
        //    foreach (User mVPres in iUserService.All())
        //    {
        //        AddEditUser mTemp = new AddEditUser();
        //        //Code for mapping
        //        mUserList.Add(mTemp);
        //    }
        //    mManagement.Items.List = mUserList.ToList();
        //    return mManagement;
        //}
        //public UserManagement GetCreateModel()
        //{
        //    mManagement.AddEditModel = new AddEditUser();
        //    return mManagement;
        //}
        //public UserManagement GetCurrentModel(AddEditUser Model)
        //{
        //    mManagement.AddEditModel = Model;
        //    return mManagement;
        //}
        //public bool Create(AddEditUser Model)
        //{
        //    mManagement.AddEditModel = Model;
        //    //Imlement this
        //    return false;
        //}
        //public UserManagement GetUpdateModel(int ID)
        //{
        //    mManagement.Items.SelectedIndex = ID;
        //    mManagement.AddEditModel = new AddEditUser();
        //    //Imlement this
        //    return mManagement;
        //}
        //public bool Update(AddEditUser Model)
        //{
        //    mManagement.Items.SelectedIndex = Model.ID;
        //    //if (UpdateVPRes(Model.ID, Model.UserName, Model.Name, Model.Comment))
        //    //{ GetList(); return true; }
        //    return false;
        //}

    }
}
